// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { game } from "../../../../script/game/control/game";
import { gambleType } from "../../../../script/game/gameType";
import { ListItem } from "../../../../script/util/ListView/ListItem";
import { ccs } from "../../../../script/util/services";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends ListItem<gambleType> {
    

    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.Label)
    desc: cc.Label = null;

    @property(cc.Label)
    power: cc.Label = null;
    
    @property(cc.Label)
    price: cc.Label = null;

    @property(cc.Node)
    icon: cc.Node = null;

    start () {

    }
    initItem(data: gambleType, index: number) {
        ccs.spriteExd.setSprite(this.icon, ccs.resMgr.getGambleIcon(data.id));
        this.title.string = data.name;
        this.desc.string = data.desc;
        this.power.string = data.power.toString();
        this.price.string = ccs.gf.getOmitNum(data.money);
    }
    onItemclick(data: gambleType) {
        if(game.playerMgr.heroInfo.age < 16) {
            return ccs.winMgr.showWin("toast", {msg: "成年以后才可以进入娱乐场所哦"});
        }
        if(game.playerMgr.heroInfo.money < data.money ) {
            ccs.winMgr.showWin("toast", {msg: '您的财富没有达到门槛'});
            game.recordMgr.addList({name: "你", action: "看了看，保安看你穷酸样赶走了你。", location: "东华娱乐城"});
            return ;
        }
        if(game.playerMgr.heroInfo.power < data.power) {
            ccs.winMgr.showWin("toast", {msg: '精力不够'});
            game.recordMgr.addList({name: "你", action: "看了看，实在是太累了，回家睡觉吧", location: "东华娱乐城"});
            return ;
        }
        game.playerMgr.reducePower(data.power);
        if(data.id == 'guess') {
            ccs.winMgr.showWin("gambleGuessWin", {type: "guess"});
            game.recordMgr.addList({name: "你", action: "进入了火眼精金牌桌，大展牌技", location: "东华娱乐城"});
            
        } else if(data.id == 'size') {
            ccs.winMgr.showWin("gambleGuessWin", {type: "size"});
            game.recordMgr.addList({name: "你", action: "进入了赌大小牌桌，大展牌技", location: "东华娱乐城"});
        }
    }
}
